<?php
/**
 * User: wenlei
 * Date: 2018/04/25
 * function: 公共继承
 */

namespace app\api\controller;

use think\Controller;
use think\Db;


class Base extends Controller
{
    
    public function _initialize()
    {
        //控制器、方法
        /*$tp = request()->controller();
        $op = request()->action();
        $this->assign("tp",$tp);   
        $this->assign("op",$op);  

        //查询左侧菜单栏
        $menu = Db::query('select * from admin_menu where pid=0'); 
        foreach ($menu as $k => $v) {
            $id = $v['id'];
            $menu[$k]['data']= Db::query("select * from admin_menu where pid = $id");
        } 
        // print_r($menu);
        $this->assign("menu",$menu); 

        //登录判断  BaseindexController
        $uid = Cookie::get('admin_userid_tp5');
        // echo $uid;
        if($uid){
            $admin_user_info = Session::get('admin_userinfo_tp5'.$uid);
            if (!$admin_user_info) {
                Cookie::delete('admin_userid_tp5');
                $this->redirect("admin/login");
            }else{
                $this->assign("admin_user_info",$admin_user_info);  
            }
        }else{
            $this->redirect("admin/login");
            // echo "<Script>alert('未登录!');</Script>"
        }*/
    }
    /* 退出登录*/
    public function outlogin()
    {
        $uid = Cookie::get('admin_userid_tp5');
        //删Cookie、Session
        Cookie::delete('admin_userid_tp5');
        Session::set('admin_userinfo_tp5'.$uid,'');

        $this->redirect("admin/login");
    }

    /*public function check_priv()
    {
        $ctl = CONTROLLER_NAME;
        $act = ACTION_NAME;
        $act_list = session('act_list');
        // 无需验证的操作
        $uneed_check = [
            'login',
            'logout',
            'vertifyHandle',
            'vertify',
            'imageUp',
            'upload',
            'login_task',
            'forget_pwd'
        ];
        if ($ctl == 'Index' || $act_list == 'all') { // 后台首页控制器无需验证,超级管理员无需验证
            return true;
        } else if (strpos($act, 'ajax') || in_array($act, $uneed_check)) { // 所有ajax请求不需要验证权限
            return true;
        } else {
            $right = SystemMenu::where("id in ($act_list)")->field('right')->cache(true)->select();

            $role_right = '';
            foreach ($right as $val) {
                $role_right .= $val . ',';
            }
            $role_right = explode(',', $role_right);
            //检查是否拥有此操作权限
            if (!in_array($ctl . '@' . $act, $role_right)) {
                $this->error('您没有操作权限' . ($ctl . '@' . $act) . ',请联系超级管理员分配权限', url('admin/Index/welcome'));
            }
        }
    }*/

}